/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - geometry/mesh
// Copyright( c) 2015.  All Rights Reserved
//
// File:		AEBaseMesh.inl
// Author:		Gianluca Belardelli
// Date:		30/04/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AEBASEMESH_INL_
#define _AEBASEMESH_INL_

AE_FORCEINLINE void AEBaseMesh::SetBoundingBox( const AEBoundingBox &bbBox )
{
	m_bbBoundingBox = bbBox;
}

AE_FORCEINLINE const AEBoundingBox &AEBaseMesh::GetBoundingBox( void ) const
{
	return m_bbBoundingBox;
}


AE_FORCEINLINE AEMeshBuffer *AEBaseMesh::GetMeshBuffer( void ) const
{ 
	return m_spMeshBuffer;
}

AE_FORCEINLINE void AEBaseMesh::SetMeshBuffer( AEMeshBuffer *lpMesh )
{
	m_spMeshBuffer = lpMesh;
	UpdateStreamMasks();
}

AE_FORCEINLINE void AEBaseMesh::UpdateStreamMasks( void )
{
	if (m_spMeshBuffer)
		m_nMeshBufferStreamMask = m_spMeshBuffer->GetStreamMask();
	else
		m_nMeshBufferStreamMask = 0;
}

AE_FORCEINLINE AEINT32 AEBaseMesh::GetMeshBufferStreamMask( void ) const 
{
	return m_nMeshBufferStreamMask;
}

AE_FORCEINLINE AEINT32 AEBaseMesh::GetMeshIndexType( void ) const 
{
	return m_spMeshBuffer ? m_spMeshBuffer->GetIndexType() : AEINDEXFORMAT_16; 
}

AE_FORCEINLINE AEINT32 AEBaseMesh::GetSubmeshCount( void ) const 
{ 
	return m_nNumSubmeshes; 
}

AE_FORCEINLINE AEINT32 AEBaseMesh::GetNumOfVertices( void ) const 
{ 
	return m_spMeshBuffer ? m_spMeshBuffer->GetVertexCount() : 0; 
}

AE_FORCEINLINE AEINT32 AEBaseMesh::GetNumOfTriangles( void ) const 
{ 
	return m_spMeshBuffer ? m_spMeshBuffer->GetCurrentPrimitiveCount() : 0; 
}

AE_FORCEINLINE AEINT32 AEBaseMesh::GetMaterialIndex( AEMaterial *lpMaterial )
{
	for( AEINT32 i = 0; i < m_nNumMaterials; i++ )
	{
		if( m_lplpMaterialRefs[i] == lpMaterial )
			return i;
	}
	return -1;
}

AE_FORCEINLINE AEMaterial *AEBaseMesh::GetMaterialByName( const char *lpszMaterialName ) const
{
	AEINT32 nIndex = GetMaterialIndexByName( lpszMaterialName );
	return ( nIndex < 0 ) ? AENULL : GetMaterial( nIndex );
}

AE_FORCEINLINE AEMaterial **AEBaseMesh::GetMaterialArray( void ) const
{
	return m_lplpMaterialRefs;
}

AE_FORCEINLINE AEMaterial *AEBaseMesh::GetOwnMaterialList( void ) const
{
	return m_lpMaterial;
}

AE_FORCEINLINE AEMaterial *AEBaseMesh::GetMaterial( AEINT32 nIndex ) const
{
	AEASSERT( nIndex >= 0 && nIndex < m_nNumMaterials );
	return m_lplpMaterialRefs[ nIndex ];
}

AE_FORCEINLINE AEINT32 AEBaseMesh::GetMaterialCount( void ) const 
{
	return m_nNumMaterials;
}

#endif // _AEBASEMESH_INL_

